using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace TestWidget
{
    public partial class TestViewStateError : System.Web.UI.Page
    {
        protected override void OnInit(EventArgs e)
        {
            if (!IsPostBack)
            {
                Button btnClickMe = new Button();
                Button bt = new Button();
                MyButton2 bt2 = new MyButton2();
                form1.Controls.Add(bt2);
                
                bt2.MyName = "Nguyen Huu Huy";
                bt2.Text = "Test Form thi install";
                form1.Controls.AddAt(0,btnClickMe);
                form1.Controls.AddAt(0, bt);
                bt.Text = "Hello World";
                btnClickMe.Text = "Click Me Button";
                btnClickMe.Attributes.Add("commentName", "click me");
                btnClickMe.Attributes.Add("Number Of Controls", form1.Controls.Count.ToString());
            }

            MyButton1 bt1 = new MyButton1();
            form1.Controls.Add(bt1);
            base.OnInit(e);
        }
    }
    [ViewStateModeById]
    public partial class MyButton1 : System.Web.UI.WebControls.Button
    {
        private int _myName;
        
        public int MyName
        {
            set { _myName = value; }
            get { return _myName; }
        }
    }

    [ViewStateModeById]
    public partial class MyButton2 : System.Web.UI.WebControls.Button
    {
        private string _myName;
        
        public string MyName
        {
            set { _myName = value; }
            get { return _myName; }
        }
    }
}
